import router from "@/router";
import type { App } from "vue";
import type { PermissionOption } from "@/api/auth/typing";

export default (app: App) => {
  app.directive("auth", {
    mounted(el, binding) {
      const permissions =
        (router.currentRoute.value.meta.permissions as PermissionOption[])?.map(
          (m) => m.permissionCode
        ) || [];
      if (!permissions.includes(binding.arg)) {
        el.style.display = "none";
      }
    },
  });
};
